<template>
  <div class="myCenter-container">
    <div class="userhead">
      <img :src="src" alt>
      <span>{{username}}</span>
    </div>
    <!-- 下面的是我们的收藏 优惠券 订单 客服 -->
    <div class="btn">
      <div @click="toenshrine">
        <img src="@/assets/img/icon_wdsc_grzx.png" alt>
        <span>收藏</span>
      </div>
      <div @click="todiscount">
        <img src="@/assets/img/icon_yhq_grzx.png" alt>
        <span>优惠券</span>
      </div>
      <div @click="tomyorder">
        <img src="@/assets/img/icon_wddd_grzx.png" alt>
        <span>订单</span>
      </div>
      <div @click="customerService">
        <img src="@/assets/img/icon_lxkf_grzx.png" alt>
        <span>客服</span>
      </div>
    </div>
    <div class="main">
      <div @click="setUp" class="mainbox boxjiushi">
        <div class="mainfbox">
          <img src="@/assets/img/icon_sz_grzx.png" class="mainicon">
          <span>设置</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div @click="toshop" class="mainbox boxjiushi" v-if="status == 2">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_qhzt.png" class="mainicon">
          <span>进入商家端</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div @click="toride" class="mainbox boxjiushi" v-if="status == 1">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_qhzt.png" class="mainicon">
          <span>进入骑手端</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div @click="businessman" class="mainbox boxjiushi">
        <div class="mainfbox">
          <img src="@/assets/img/icon_cwsj_grzx.png" class="mainicon">
          <span>成为商家</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="rider">
        <div class="mainfbox">
          <img src="@/assets/img/icon_cwqs_grzx.png" class="mainicon">
          <span>成为骑手</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="Suk_tonewdis">
        <div class="mainfbox">
          <img src="@/assets/img/icon_yhq_grzx.png" class="mainicon">
          <span>优惠劵</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="exit">
        <div class="mainfbox">
          <img src="@/assets/img/icon_tc_grzx.png" class="mainicon">
          <span>退出</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      username: "Admin",
      src: require("@/assets/img/img_tx_grzx.png"),
      status: null
    };
  },
  activated() {
    this.getlist();
    this.getstatus();
  },
  created: function() {
    this.getstatus();
    this.getlist();
  },
  methods: {
    Suk_tonewdis(){
      let that = this
      that.$router.push({
        name:'newdis'
      })
    },
    //获取用户身份
    getstatus() {
      let that = this;
      // that.$toast.loading({
      //   message: "加载中..."
      // });
      var Sukdata = {
        id: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      if(Sukdata.id==null){
        localStorage.removeItem("userid");
        this.$router.push({
          path: "/login"
        });
        return
      }
      that.axios
        .post(that.baseUrl + "/user/userOne", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data);
              localStorage.getItem('userhead',res.data.data.head)
              that.status = res.data.data.status;
              localStorage.setItem("userstatus", res.data.data.status);
              localStorage.setItem("myshopid", res.data.data.dinid);
              that.src = res.data.data.head;
              that.username = res.data.data.name;
              if (res.data.data.denglvcount == 0) {
                if (res.data.data.status == 1) {
                  that.$toast({
                    message: "您已经成为骑手！"
                  });
                } else if (res.data.data.status == 2) {
                  that.$toast({
                    message: "您已经成为商家！"
                  });
                }
              } else if (res.data.data.denglvcount > 0) {
                that.$toast.clear();
              }
            } else if (res.data.meta.code == 501) {
              that.$toast.clear();
            }
          }
        });
    },
    getlist() {
      let that = this;
      console.log(123);
      that.status = localStorage.getItem("userstatus");
      var obj = {
        id: localStorage.getItem("userid")
      };
      that.axios
        .post(that.baseUrl + "/user/queryUser", that.Qs.stringify(obj), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            console.log(res.data, "user");
            if (res.data.meta.code == 200) {
            } else {
              console.log("fail");
            }
          }
        });
    },
    // 下面的是到我的订单去
    tomyorder() {
      this.$router.push({
        name: "myOrder"
      });
    },
    exit() {
      console.log(123);
      this.$dialog
        .confirm({
          title: "退出",
          message: "确定退出"
        })
        .then(() => {
          localStorage.removeItem("userid");
          this.$router.push({
            path: "/login"
          });
          // on confirm
        })
        .catch(() => {
          // on cancel
        });
    },
    toenshrine() {
      this.$router.push({
        name: "enshrine"
      });
    },
    todiscount() {
      this.$router.push({
        name: "discount"
      });
    },
    setUp() {
      this.$router.push({
        name: "setUp"
      });
    },
    businessman() {
      this.$router.push({
        name: "businessman"
      });
    },
    toride() {
      let that = this;
      let userstatus = localStorage.getItem("userstatus");
      if (userstatus == 1) {
        that.$router.push({
          name: "ride"
        });
      } else {
        that.$toast({
          message: "没有骑手资格"
        });
      }
    },
    toshop() {
      let that = this;
      console.log("tosh");
      let userstatus = localStorage.getItem("userstatus");
      if (userstatus == 2) {
        that.$router.push({
          name: "shop"
        });
      } else {
        that.$toast({
          message: "没有商家资格"
        });
      }
    },
    rider() {
      this.$router.push({
        name: "rider"
      });
    },
    customerService() {
      this.$router.push({
        name: "kefu"
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.myCenter-container {
  width: 100%;
  height: 100%;
  background: #f4f4f4;
}

.boxjiushi {
  width: 90%;
  margin: 0 auto;
}

.righticon {
  width: 9px;
  height: 18px;
  vertical-align: middle;
  margin-left: 10px;
}

.header {
  background: #fff;
  padding: 10px 5%;
}

.userhead {
  width: 100%;
  text-align: center;
  font-size: 18px;
  padding-top: 15px;
  padding-bottom: 15px;
  background: #ffffff;
}
.userhead > img {
  display: block;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  margin: 0 auto;
  margin-bottom: 5px;
}
.btn {
  width: 90%;
  margin: 0 auto;
  background: #fff;
  border-radius: 20px;
  padding-top: 10px;
  padding-bottom: 10px;
  margin-top: 15px;
  margin-bottom: 15px;
}
.btn > div {
  width: 25%;
  float: left;
  text-align: center;
  font-size: 14px;
}
.btn > div > img {
  display: block;
  width: 50%;
  margin: 0 auto;
  margin-bottom: 5px;
}
.btn:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.userinfo {
  display: inline-block;
  vertical-align: middle;
  margin-left: 5px;
}
span {
  color: #737373;
}
.username {
  font-size: 18px;
}

.bannerbox {
  width: 88%;
  margin: 0 auto;
}

.listicon {
  width: 50px;
  height: 50px;
  margin-bottom: 3px;
}

.banner {
  padding: 12px 0;
  overflow: hidden;
}

.bannerbox {
  display: flex;
  justify-content: space-around;
}

.sbox {
  display: inline-block;
  text-align: center;
  .listtit {
    color: #1fadff;
  }
}

.main {
  background: #fff;
  .mainfbox {
    display: inline-block;
  }
  .mainbox {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f4f4f4;
  }
  .righticon {
    margin-right: 20px;
  }
  .mainicon {
    width: 28px;
    height: 28px;
    vertical-align: middle;
  }
  span {
    display: inline-block;
    font-size: 17px;
    line-height: 17px;
    height: 100%;
    vertical-align: middle;
    line-height: 100%;
    margin-left: 15px;
  }
}
</style>

